package net.lab1024.sa.admin.module.business.supercomputer.datasource.controller;

import net.lab1024.sa.admin.module.business.supercomputer.datasource.domain.form.DatasourceAddForm;
import net.lab1024.sa.admin.module.business.supercomputer.datasource.domain.form.DatasourceQueryForm;
import net.lab1024.sa.admin.module.business.supercomputer.datasource.domain.form.DatasourceUpdateForm;
import net.lab1024.sa.admin.module.business.supercomputer.datasource.domain.vo.DatasourceVO;
import net.lab1024.sa.admin.module.business.supercomputer.datasource.service.DatasourceService;
import net.lab1024.sa.base.common.domain.RequestUser;
import net.lab1024.sa.base.common.util.SmartRequestUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import cn.dev33.satoken.annotation.SaCheckPermission;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 111 Controller
 *
 * @Author zxp
 * @Date 2024-09-27 09:37:05
 * @Copyright 11111
 */

@RestController
@Tag(name = "111")
public class DatasourceController {

    @Resource
    private DatasourceService datasourceService;

    @Operation(summary = "分页查询 @author zxp")
    @PostMapping("/datasource/queryPage")
    @SaCheckPermission("datasource:query")
    public ResponseDTO<PageResult<DatasourceVO>> queryPage(@RequestBody @Valid DatasourceQueryForm queryForm) {
        return ResponseDTO.ok(datasourceService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author zxp")
    @PostMapping("/datasource/add")
    @SaCheckPermission("datasource:add")
    public ResponseDTO<String> add(@RequestBody @Valid DatasourceAddForm addForm) {
        return datasourceService.add(addForm);
    }

    @Operation(summary = "更新 @author zxp")
    @PostMapping("/datasource/update")
    @SaCheckPermission("datasource:update")
    public ResponseDTO<String> update(@RequestBody @Valid DatasourceUpdateForm updateForm) {
        return datasourceService.update(updateForm);
    }


    @Operation(summary = "单个删除 @author zxp")
    @GetMapping("/datasource/delete/{dataSourceId}")
    @SaCheckPermission("datasource:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Integer dataSourceId) {
        return datasourceService.delete(dataSourceId);
    }
}
